// 公共JS

function U() {
    var url = arguments[0] || [];
    var param = arguments[1] || {};
    var url_arr = url.split('/');
    if (!$.isArray(url_arr) || url_arr.length < 2 || url_arr.length > 3) {
        return '';
    }
    if (url_arr.length == 2) url_arr.unshift(_GROUP_);
    var pre_arr = ['g', 'm', 'a'];
    var arr = [];
    for (d in pre_arr) arr.push(pre_arr[d] + '=' + url_arr[d]);
    for (d in param) arr.push(d + '=' + param[d]);
    return _APP_ + '?' + arr.join('&');
}

/**
 * json转数组
 */
function jsonToArray(json) {
    // 转化成obj
    var obj = eval(json);
    // 转化成数组
    var arr = new Array();
    for (var i = 0; i < obj.length; i++) {
        arr.push(obj[i]);
    }
    return arr;
}

/**
 * 字符串转时间戳
 */
function datetimeToUnix(datetime) {
    var d = datetime.replace(/-/g, '/');
    var timestamp = new Date(d).getTime();
    var res = parseInt(timestamp / 1000);
    return res;
}

/**
 * 时间戳转字符串
 */
function unixToDatetime(unix) {
    var timestamp = parseInt(unix);
    var d = new Date(timestamp * 1000); //根据时间戳生成的时间对象
    var yy = d.getFullYear(); //年
    var mm = d.getMonth() + 1; //月
    var dd = d.getDate(); //日
    var hh = d.getHours(); //时
    var ii = d.getMinutes(); //分
    var ss = d.getSeconds(); //秒
    var date = yy + "-";
    if (mm < 10) date += "0";
    date += mm + "-";
    if (dd < 10) date += "0";
    date += dd + " ";
    if (hh < 10) date += "0";
    date += hh + ":";
    if (ii < 10) date += '0';
    date += ii + ":";
    if (ss < 10) date += '0';
    date += ss;
    return date;
}

/**
 * 获取当前时间字符串
 */
function getLocalTime(format) {
    var now = new Date();
    var yy = now.getFullYear(); //年
    var mm = now.getMonth() + 1; //月
    var dd = now.getDate(); //日
    var hh = now.getHours(); //时
    var ii = now.getMinutes(); //分
    var ss = now.getSeconds(); //秒
    var clock = yy + "-";
    if (mm < 10) clock += "0";
    clock += mm + "-";
    if (dd < 10) clock += "0";
    clock += dd + " ";
    // if(hh < 10) clock += "0";
    // clock += hh + ":";
    // if (ii < 10) clock += '0';
    // clock += ii + ":";
    // if (ss < 10) clock += '0';
    // clock += ss;
    return clock;
}

/**
 * 格式化时间
 * @return {[type]}   [description]
 */
function formatDateTime(unix) {
    var now = new Date(parseInt(unix) * 1000);
    return now.toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
}